﻿using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;

namespace TelerikAcademyOopProject
{
    public class TraderManager
    {
        Dictionary<string, Trader> traderList = new Dictionary<string, Trader>();

        public void TraderRegistration(string userame,string password)
        {}

        public void TraderLogin(string username,string password)
        {
            var getResult = from x in traderList where (x.Value.Equals(x.Value.Name)) select x;

            if (!getResult.Any())
            {
                throw new StockException("This user dowsnot exist Pleas Register in the Susttem");
            }
            else
            {
                Console.WriteLine("OK You are In");
            }
        }

        public void AddUser(string traderType, string traderId, string traderName,string traderPass,Account traderAccount,StockManager sm)
        {
            // get newi created Object
            var trader = TraderFactory.setNewTrader(traderType);
            
            // set new trader propterties
            trader.setTraderProperties(traderId, traderName, traderPass,traderAccount,sm);

            // add it to the list of traders
            traderList.Add(trader.Id, trader);
        }

        public void RemoveUser(string id)
        {
            this.traderList.Remove(id);
        }


        public void buyItem(Buyer trader,string itemId)
        {
            // buy an item by it's ID;
            //trader.BuyItem(itemId);
        }

        public void showTraders()
        {
            if (this.traderList.Count != 0)
            {
                foreach (var item in this.traderList)
                {
                    Console.WriteLine(item.Value);
                }
            }
            else
            {
                Console.WriteLine("No traders are avalabel");
            }
        }

    }
}
